<template>
  <div class="nav-header">
    <i
      class="fold-menu"
      :class="isFlod ? 'el-icon-s-fold' : 'el-icon-s-unfold'"
      @click="handleFoldClick"
    ></i>
    <cky-bread-crumb :breadcrumbs="breadcrumb" class="content" />
    <div class="lostLogin" @click="lostLogin">推出登录</div>
  </div>
</template>

<script lang="ts" setup>
import { ref, defineEmits, computed } from 'vue'
import ckyBreadCrumb from '@/base-ui/breadcrumb'
import { useRoute, useRouter } from 'vue-router'
import { useStore } from '@/store'
import { pathMapBreadcrumbs } from '@/untils/map-menus'
import LocalCache from '@/untils/cache'

const emits = defineEmits(['foldChange'])
const route = useRoute()
const router = useRouter()
const store = useStore()

const isFlod = ref<boolean>()
const handleFoldClick = () => {
  isFlod.value = !isFlod.value
  emits('foldChange', isFlod.value)
}

const breadcrumb = computed(() => {
  const userMenus = store.state.login.userMenu
  const currentPath = route.path
  return pathMapBreadcrumbs(userMenus, currentPath)
})

const lostLogin = () => {
  LocalCache.clearCache()
  router.push('/main')
}
</script>

<style scoped lang="less">
.nav-header {
  display: flex;
  width: 100%;
  .fold-menu {
    font-size: 30px;
    cursor: pointer;
  }
  .content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex: 1;
    padding: 0 20px;
  }
}
.lostLogin {
  float: right;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
</style>
